package cn.tedu.service.impl;

import cn.tedu.entity.MenusEntity;
import cn.tedu.mapper.MenuMapper;
import cn.tedu.mapper.RoleMenuMapper;
import cn.tedu.mapper.UserRoleMapper;
import cn.tedu.service.MenuService;
import cn.tedu.vo.Node;
import cn.tedu.vo.SysUserMenu;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class MenuServiceImpl  extends ServiceImpl<MenuMapper,MenusEntity> implements MenuService {

    @Autowired
    private RoleMenuMapper roleMenuMapper;

    @Autowired
    private UserRoleMapper userRoleMapper;

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public List<SysUserMenu> findUserMenusByUserId(int i) {
        // 根据用户id 找到角色id
        List<Integer> roleIds = userRoleMapper.findRoleIdsByUserId(i);
        // 根据角色id 找到菜单id
        List<Integer> menuIds = roleMenuMapper.findMenusByRoleIds(roleIds);
        // 返回用户的所有菜单
        return menuMapper.findMenuByIds(menuIds);
    }

    @Override
    public List<MenusEntity> findObjects() {
        List<MenusEntity> list= menuMapper.findObjects();
        return list;
    }

    @Override
    public List<Node> doFindZtreeMenuNodes() {

        return menuMapper.doFindZtreeMenuNodes();
    }

}
